<template>
	<view class="withdrawal">
		<n-loading></n-loading>
		<view v-if="memberInfo">
			<view class="withdrawalInBox">
				<view class="withdrawalIn">
					<view class="arrivalTips">
						<view class="tit">到账账户</view>
						<view class="tips">
							<view>微信零钱</view>
							<view class="tips2">2小时内到账</view>
						</view>
					</view>
					<view class="tit">提现金额</view>
					<view class="inBox">
						<text class="unit">￥</text>
						<input class="inputGo" type="number" :value="amount" @input="fillAmount" />
					</view>
					<view class="tips">
						<u-icon name="info-circle" color="#999" size="27"></u-icon>						
						可提现金额为{{memberInfo.amount==null?0:memberInfo.amount}}元,
						<text class="allWithdrawal" @tap="fullWithdrawal">全部提现</text>
					</view>
					<view class="withdrawBtn" @tap="immediate">立即提现</view>
				</view>
				<view class="tipsBox">
					<view class="tips">每次只可提现{{memberInfo.withdrawal_apply_limit}}元以上金额</view>
					<view class="tips">输入【可提现】金额范围内的数值，提现金额将转账到用户微信零钱。</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				memberInfo:null,
				// 体现金额
				amount:'',
			}
		},
		onLoad: function (option) {
			this.getMemberInfo();
		},
		methods: {
			getMemberInfo(){
				this.apiget('/fun/member/view',{}).then(res =>{
					if(res.data.status == 200 ) {
						this.memberInfo = res.data.data;
					}
				})
			},
			// 全部提现
			fullWithdrawal(){
				this.amount = parseInt(this.memberInfo.amount)
			},
			// 手动输入
			fillAmount(e){
				this.amount = e.detail.value;
			},
			// 立即提现
			immediate(){
				var regTest = /^[1-9]\d*$/;//正整数
				if (!regTest.test(this.amount) || parseInt(this.amount)<parseInt(this.memberInfo.withdrawal_apply_limit)){
					uni.showToast({
						icon: 'none',
						duration:1000,
						title: '请输入大于等于'+this.memberInfo.withdrawal_apply_limit+'的整数金额'
					});
					return false;
				}
				this.apipost('/fun/member/withdrawal',{amount:this.amount}).then(res =>{
					if(res.data.status == 200 ) {
						uni.showToast({
							icon: 'success',
							duration:1000,
							title: res.data.message,
							success: res => {
								setTimeout(function (){
									uni.navigateBack({
									    delta: 1
									});
								}, 1000);
							},
						});
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.withdrawal{
		min-height: 100%;
		padding-top: 32rpx;
		background: #F8F8FA;
	}
	
	.withdrawalInBox{
		padding: 0 32rpx;
		
		.withdrawalIn{
			padding: 24rpx 32rpx;
			background: #FFFFFF;
			box-shadow: 0px 8rpx 16rpx rgba(0, 0, 0, 0.04);
			border-radius: 16rpx;
		
			.arrivalTips{
				padding: 24rpx 0;
				margin-bottom: 16rpx;
				display: flex;
				.tit{
					margin-right: 32rpx;
					font-size: 28rpx;
					line-height: 44rpx;
					color: #333333;
				}
				.tips{
					font-size: 28rpx;
					line-height: 44rpx;
					color: #FF5238;
					
					.tips2{
						font-size: 24rpx;
						line-height: 36rpx;
						color: #666666;
					}
				}
			}
			
			.tit{
				font-size: 28rpx;
				line-height: 44rpx;
				color: #333333;
			}
			
			.inBox{
				padding-top: 22rpx;
				margin-bottom: 25rpx;
				display: flex;
				align-items: center;
				border-bottom: 1rpx solid #F5F5F5;
				
				.unit{
					font-size: 48rpx;
					color: #333333;
				}
				
				.inputGo{
					flex: auto;
					border-left: 2rpx solid #666;
					padding-left: 14rpx;
				}
			}
			
			.tips{
				margin-bottom: 48rpx;
				font-size: 26rpx;
				line-height: 44rpx;
				color: #7F7F7F;
				.u-icon{
					margin-right: 10rpx;
				}
				
				.allWithdrawal{
					margin-left: 8rpx;
					color: #5B6B8C;
				}
			}
			
			.withdrawBtn{
				width: 100%;
				height: 96rpx;
				background: #FF5238;
				border-radius: 70rpx;
				font-size: 32rpx;
				color: #FFFFFF;
				line-height: 96rpx;
				text-align: center;
			}
			
		}
		.tipsBox{
			margin-top: 62rpx;
			
			.tips{
				position: relative;
				padding-left: 32rpx;
				margin-bottom: 36rpx;
				font-size: 28rpx;
				line-height: 44rpx;
				color: #666666;
			}
			.tips:before{
				position: absolute;
				content: '';
				top: 10rpx;
				left: 0;
				width: 8rpx;
				height: 24rpx;
				background-color: #FF5238;
			}
		}
	}
</style>
